#include <iostream>
#include <assert.h>
#include <stdlib.h>

#include "DArray.hpp"

DArray::DArray(const int size)
{
  if(size == 0)
  {
    std::cerr<<"ERROR: Can not construct a zero length array."<<std::endl;
    assert(0);
  }
  msize = size;
  arrayPtr = new double[msize];
  for( int i=0; i< msize; i++ )
    arrayPtr[i] = 0.0;
  
};

DArray::~DArray()
{
  delete [] arrayPtr;
};

int DArray::size() const
{
  return msize;
};

const double& DArray::operator[](int index) const
{
  if(index>msize)
  {
    std::cerr<<"Error: index out of bounds in DArray"<<std::endl;
    assert(0);
  }
  return arrayPtr[index];
};

double& DArray::operator[](int index)
{
  if(index>msize)
  {
    std::cerr<<"Error: index out of bounds in DArray"<<std::endl;
    assert(0);
  }
  return arrayPtr[index];
};

DArray& DArray::operator+=(const DArray& rhs)
{
  assert( msize == rhs.size() );
  for( int i=0; i<msize; i++ )
  {
    arrayPtr[i] += rhs[i];
  }
  return  *this;
};

DArray& DArray::operator*=(const double& rhs)
{
  for(int i=0;i<msize;i++)
    arrayPtr[i] = arrayPtr[i]*rhs;
  return *this;
};

void DArray::print()
{
  for(int i=0; i<msize; i++)
    std::cout<<arrayPtr[i]<<'\t';
  std::cout<<std::endl;
};



















